package org.vectrics.recruiter.data;

import java.util.Date;

import org.apache.log4j.Logger;
import org.vectrics.SystemException;
import org.vectrics.provider.CoreServiceLocator;
import org.vectrics.user.Person;
import org.vectrics.user.PersonCommunication;
import org.vectrics.user.PersonCommunicationMethod;
import org.vectrics.user.PersonCommunicationMethodType;
import org.vectrics.user.PersonEncounterStatusType;

public class TestPhoneCallGenerator {
	private Logger log = Logger.getLogger(this.getClass());
	
	public void addPersonPhoneCall(Person person, Person leadPerson, Date startDate, long minutes) {
		Date endDate = new Date(startDate.getTime() + (1000 * 60 * minutes));
		log.info("Creating phone call from: " + leadPerson + "  to: " + person);
		PersonCommunication communication = new PersonCommunication();
		communication.setPerson(person);
		communication.setLeadPerson(leadPerson);
		communication.setDirection(PersonCommunication.DIRECTION_TO);
		PersonEncounterStatusType doneStatus = CoreServiceLocator.getPersonService().findPersonEncounterStatusType(PersonEncounterStatusType.STATUS_DONE);
		communication.setEncounterStatus(doneStatus);
		
		PersonCommunicationMethodType methodType = CoreServiceLocator.getPersonService()
			.findPersonCommunicationMethodType(PersonCommunicationMethodType.TYPE_PHONE_CALL);
		if (methodType == null)
			throw new SystemException("Could not find communication method");
		PersonCommunicationMethod method = new PersonCommunicationMethod();
		method.setPersonCommunicationMethodType(methodType);
		communication.setMethod(method);
		communication.setDateStart(startDate);
		communication.setDateEnd(endDate);
		CoreServiceLocator.getPersonService().updatePersonCommunication(communication);
	}
}
